<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	add.php
// Last Modification Time	:	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications  :
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
if (eregi("add.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}

if (!isAdmin()) {
  header ("Location:$SITE_URL/");
	exit;
}
?>
<!--div:icerik -->
    <div id="icerik">
    <p>
<?php
if (empty($_POST)) { # bilgi girişi için kullanıcıya uygun formları göster
  $what=@trim($_GET['what']);
  if (!empty($what)) {
    $dil=listLangs();
    if ($what!='item' && $what!='brand')
      echo '<form method="post" action="index.php?page=add" id="addForm" class="box">'
          .'<input type="hidden" name="what" value="'.$what.'" />';
/**************************************************************************************************************************************/
    if ($what=='page') { # sayfa ekle
      // id, title, content, info, name, date, order, active, lang
      echo '<h1>Sayfa Ekle</h1><br />';
      echo <<<html
        <label>Başlık:</label> <input type="text" maxlength="25" name="title" id="title" /><br />
        <label>Açıklama:</label> <input type="text" maxlength="100" name="info" id="info" class="input-text" /><br />
        <label>İçerik:</label> <textarea name="content" id="content" rows="15" class="textarea"></textarea><br />
        <label>Sıra:</label> <input type="text" maxlength="5" name="order" id="order" class="input-mini" /> &nbsp;&nbsp; Dil: $dil&nbsp;&nbsp;
        &nbsp;&nbsp;Aktif: <input type="checkbox" name="active" id="active" value="1" checked class="checkbox" /><br />
        <label></label><input type="submit" value=" Yeni Sayfayı Kaydet " id="save" class="input-submit" />
html;
    }
/**************************************************************************************************************************************/
    elseif ($what=='maincat') { # ana menü ekle
      // id, title, info, name, active, parent, order, lang, date
      echo '<h1>Ana Kategori Ekle</h1><br />';
      echo <<<html
        <label>Başlık:</label> <input type="text" maxlength="75" name="title" id="title" /><br />
        <label>Açıklama:</label> <input type="text" maxlength="150" name="info" id="info" class="input-text" /><br />
        <label>Sıra:</label> <input type="text" maxlength="5" name="order" id="order" class="input-mini" /> &nbsp;&nbsp; Dil: $dil&nbsp;&nbsp;
        &nbsp;&nbsp;Aktif: <input type="checkbox" name="active" id="active" value="1" checked class="checkbox" /><br />
        <label></label><input type="submit" value=" Yeni Kategoriyi Kaydet " id="save" class="input-submit" />
html;
    }
/**************************************************************************************************************************************/
    elseif ($what=='subcat') { # alt menü ekle
      $cat_id=@(int)$_GET['cat_id'];
      $q=$mysql->query("select title from $CATEGORIES_TABLE where id='$cat_id'");
      $title=$prep->html($mysql->result($q,'title'));
      if ($title) {
        echo '<h1>Alt Kategori Ekle</h1><br />';
        echo <<<html
          <input type="hidden" name="parantCat" value="$cat_id" />
          <label>Ana Kategori:</label> <label>$title</label><label>&nbsp;</label> <br />
          <label>Başlık:</label> <input type="text" maxlength="75" name="title" id="title" /><br />
          <label>Açıklama:</label> <input type="text" maxlength="150" name="info" id="info" class="input-text" /><br />
          <label>Sıra:</label> <input type="text" maxlength="5" name="order" id="order" class="input-mini" /> &nbsp;&nbsp; Dil: $dil&nbsp;&nbsp;
          &nbsp;&nbsp;Aktif: <input type="checkbox" name="active" id="active" value="1" checked class="checkbox" /><br />
          <label></label><input type="submit" value=" Alt Kategoriyi Kaydet " id="save" class="input-submit" />
html;
      }
      else echo '<br />Geçersiz kategori<br />';
    }
/**************************************************************************************************************************************/
    elseif ($what=='exchange') { # kur ekle
      // id, name, exchange, date, active
      echo '<h1>Kur İşlemleri</h1><br />';
      echo <<<html
        <input type="hidden" name="do" id="do" value="add" />
        <input type="hidden" name="id" id="id" value="0" />
        <label>Kur Adı:</label> <input type="text" maxlength="10" name="name" id="name" /><br />
        <label>Kur:</label> <input type="text" maxlength="5" name="exchange" id="exchange" class="input-mini" /> &nbsp;&nbsp;&nbsp;
        &nbsp;Aktif: <input type="checkbox" name="active" id="active" value="1" checked class="checkbox" /><br />
        <label></label><input type="submit" value=" Yeni Kuru Kaydet " id="exsave" class="input-submit" /><br /><br /><br />
        <table width="50%" cellpadding="0" cellspacing="0" style="margin-left:100px;" id="extable">
        <tr><th width="20">&nbsp;&nbsp;</th><th width="20">&nbsp;&nbsp;</th><th>&nbsp;Kur Adı&nbsp;</th><th>&nbsp;Kur&nbsp;</th>
        <th align="center">&nbsp;Tarih&nbsp;</th><th width="20">&nbsp;&nbsp;</th></tr>
html;
      $q=$mysql->query("select * from $EXCHANGES_TABLE order by name asc");
      while ($read=$mysql->fetch($q)) {
      	$id=$read['id'];
      	$name=$prep->html($read['name']);
      	$exchange=$read['exchange'];
      	$date=$read['date'];
      	$active=$read['active'];

      	$date=strftime("%d %b %y %a %H:%M",$date);
      	$date=iconv("ISO-8859-9", "UTF-8",$date);
      	if ($active=='1') $active='<img src="template/img/active.gif" title="Aktif" />';
      	else $active='<img src="template/img/notactive.gif" title="Aktif Değil" />';

      	echo <<<html
      	<tr id="sira$id">
          <td align="center"><img src="template/img/delete.gif" title="Sil" class="adminicon" alt="$id" /></td>
          <td align="center"><img src="template/img/edit.gif" title="Düzenle" class="adminicon" alt="$id" /></td>
          <td >$name</td>
          <td align="right">$exchange</td>
          <td align="right">$date</td>
          <td align="center">$active</td>
        </tr>
html;
      }
      echo '</table><br />';
    }
/**************************************************************************************************************************************/
    elseif ($what=='options') { # ayar güncelle
      echo '<h1>Genel Ayarlar</h1><br />';
      $q=$mysql->query("select * from $OPTIONS_TABLE order by id asc");
      if ($mysql->numRows($q)>0) {
        while ($read=$mysql->fetch($q)) {
          $id=$read['id'];
          $title=$prep->html($read['title']);
          $option=strtolower($read['option']);
          $value=$prep->html($read['value']);
          $type=$read['type'];

          if ($type=='text')
            echo '<label>'.$title.':</label> <input type="text" maxlength="255" name="'.$option.'" value="'.$value.'" class="input-text" /><br />';
          if ($type=='radio') {
            $s1='checked';
            $s2='';
            if ($value==0||empty($value)) {
              $s1=$s2;
              $s2='checked';
            }
            echo '<label>'.$title.':</label> &nbsp;&nbsp;';
            echo 'Evet &nbsp;<input type="radio" name="'.$option.'" value="1" '.$s1.' class="radio" />&nbsp;&nbsp;&nbsp;&nbsp;';
            echo 'Hayır &nbsp;<input type="radio" name="'.$option.'" value="0" '.$s2.' class="radio" />&nbsp;&nbsp;&nbsp;&nbsp;<br />';
          }
        } // while
        echo '<br /><label></label><input type="submit" value=" Ayarları Kaydet " id="save" class="input-submit" />';
      }
      else echo 'Dinamik ayar yok';
    }
/**************************************************************************************************************************************/
    elseif ($what=='brand') { # marka işlemleri
      // id, title, name, image, date, order, active
      echo '<h1>Marka İşlemleri</h1><br />';
      echo <<<html
        <form method="post" action="index.php?page=add" id="addForm" class="box" enctype="multipart/form-data">
        <input type="hidden" name="what" value="brand" />
        <input type="hidden" name="do" id="do" value="add" />
        <input type="hidden" name="id" id="id" value="0" />
        <input type="hidden" name="MAX_FILE_SIZE" value="256000" /><!-- 250KB -->
        <label>Marka Adı:</label> <input type="text" maxlength="25" name="title" id="title" /><br />
        <label>Marka Foto:</label> <input type="file" name="image" id="image" /><br />
        <label>Sıra:</label> <input type="text" maxlength="5" name="order" id="order" class="input-mini" /> &nbsp;&nbsp;
        &nbsp;&nbsp;Aktif: <input type="checkbox" name="active" id="active" value="1" checked class="checkbox" /><br />
        <label></label><input type="submit" value=" Yeni Markayı Kaydet " id="save" class="input-submit" /><br /><br /><br />
        <table width="50%" cellpadding="0" cellspacing="0" style="margin-left:100px;" id="brandtable">
        <tr><th width="20">&nbsp;&nbsp;</th><th width="20">&nbsp;&nbsp;</th><th>&nbsp;Marka Adı&nbsp;</th>
        <th align="center">&nbsp;Tarih&nbsp;</th><th width="20">&nbsp;&nbsp;</th></tr>
html;
      $q=$mysql->query("select * from $BRANDS_TABLE order by `order` asc");
      while ($read=$mysql->fetch($q)) {
      	$id=$read['id'];
      	$title=$prep->html($read['title']);
      	$image=$read['image'];
      	$date=$read['date'];
      	$active=$read['active'];

      	$date=strftime("%d %b %y %a %H:%M",$date);
      	$date=iconv("ISO-8859-9", "UTF-8",$date);
      	if ($active=='1') $active='<img src="template/img/active.gif" title="Aktif" />';
      	else $active='<img src="template/img/notactive.gif" title="Aktif Değil" />';

      	echo <<<html
      	<tr name="brand$id" id="brand$id">
          <td align="center"><img src="template/img/delete.gif" title="Sil" class="adminicon" alt="$id" /></td>
          <td align="center"><img src="template/img/edit.gif" title="Düzenle" class="adminicon" alt="$id" /></td>
          <td>$title</td>
          <td align="right">$date</td>
          <td align="center">$active</td>
        </tr>
html;
      }
      echo '</table><br />';
    }
/**************************************************************************************************************************************/
    elseif ($what=='item') { # ürün ekle
      $_SESSION['imgList']=array();
      $cat_id=@(int)$_GET['cat_id'];
      $q=$mysql->query("select title from $CATEGORIES_TABLE where id='$cat_id'");
      $title=$prep->html($mysql->result($q,'title'));
      if ($title) {
        $_SESSION['makeselection']=array();
        $brands=listBrands();
        echo <<<html
  <link rel="stylesheet" href="template/tabber.css" type="text/css" media="screen" />
  <script type="text/javascript" src="template/tabber.js"></script>
  <link rel="stylesheet" href="template/src/css/shadowbox.css" type="text/css" media="screen" />
  <script type="text/javascript" src="template/src/js/adapter/shadowbox-jquery.js"></script>
  <script type="text/javascript" src="template/src/js/shadowbox.js"></script>
  <script type="text/javascript">
  $(document).ready(function(){
    var SHBoxOptions = {
      displayNav: false,
      handleUnsupported: 'remove',
      keysClose: ['c', 27] // c or esc
    };
    Shadowbox.init(SHBoxOptions);
  });</script>

        <h1>Ürün Ekle</h1><br />
        <form method="post" action="index.php?page=add" id="addForm" class="box" enctype="multipart/form-data">
        <input type="hidden" name="what" value="item" />
        <input type="hidden" name="parantCat" value="$cat_id" />
        <input type="hidden" name="MAX_FILE_SIZE" value="256000" /><!-- 250KB -->
        <label>Ana Kategori:</label> <label>$title</label><label>&nbsp;</label> <br />
        <label>Başlık:</label> <input type="text" maxlength="100" name="title" id="title" class="input-text" /><br />
        <label>Açıklama:</label> <input type="text" maxlength="255" name="info" id="info" class="input-text" /><br />
        <label>İçerik:</label> <textarea name="content" id="content" rows="8" class="textarea"></textarea><br />
        <label>Sıra:</label> <input type="text" maxlength="5" name="order" id="order" class="input-mini" />&nbsp;&nbsp;
        Aktif: <input type="checkbox" name="active" id="active" value="1" checked class="checkbox" />&nbsp;&nbsp;
        Yeni: <input type="checkbox" name="new" id="new" value="1" checked class="checkbox" />&nbsp;&nbsp;
        Fiyat Göster: <input type="checkbox" name="show_price" id="show_price" value="1" checked class="checkbox" />&nbsp;&nbsp;
        Ana Sayfa: <input type="checkbox" name="home" id="home" value="1" class="checkbox" /><br />
        <label>Marka:</label> $brands &nbsp;&nbsp; Dil: $dil&nbsp;&nbsp;<br />
        <label>Ürün Kodu:</label> <input type="text" maxlength="45" name="xml_code" id="xml_code" /><br />
        <label>Foto Yükle:</label> <input type="file" name="image" id="image" /><br />
        <label>Foto Seç:</label> <a href="javascript:void(0);" onclick="photoSelect(0);" />Fotoğraf Seç</a><br /> <span id="images"></span><br />
        <label>Ek Kategoriler:</label> <span id="listcats"></span><input type="hidden" name="cats" id="cats" value="0" />
        <a href="javascript:void(0);" name="catselect" id="catselect" onclick="catSelect(0);">Kategori Seç</a><br /><br />
        <label></label><input type="submit" value=" Yeni Ürünü Kaydet " id="save" class="input-submit" />
html;
      }
      else echo '<br />Geçersiz kategori<br />';
    }
    echo '</form><br />';
  }
  else echo '1-geçersiz kullanım!';
}
else { # gelen bilgiyi VTye gir ##########################################################################################################
  # prepare $_POST
  foreach ($_POST as $key=>$val) $_POST[$key]=$mysql->escape($val);
  extract($_POST,EXTR_OVERWRITE);
  $date=time()+(60*$TIME_CORRECTION);
  if (!$active) $active=0;
  $valid=new Validation();

  if (!empty($what)) {
    if ($what=='page') { # sayfa ekle
      echo '<h1>Sayfa İşlemleri</h1><br />';
      $valid->inRange($title,25,1,'Başlık doldurulmalı ve en fazla 25 karakter olmalıdır.');
      $valid->inRange($info,100,1,'Açıklama doldurulmalı ve en fazla 100 karakter olmalıdır.');
      $valid->isEmpty($content,'İçerik boş bırakılamaz');
      $valid->inRange($order,5,1,'Sıra doldurulmalı ve en fazla 5 karakter olmalıdır.');
      $valid->isNumber($order,'Sıra sadece rakam olmalıdır.');

      if ($valid->isError()) $valid->listErrors();
      else {
        // id, title, content, info, name, date, order, active, lang
        $name=makeNicer($title);
        $name=checkNiceName($name,$PAGES_TABLE);
        $q=$mysql->query("insert into $PAGES_TABLE values('','$title','$content','$info','$name','$date','$order','$active','$lang')");
        if ($q) echo 'Yeni sayfa eklendi';
        else echo 'Sayfa eklenirken hata oluştu!';
      }
    }
/**************************************************************************************************************************************/
    elseif ($what=='maincat') { # ana menü ekle
      echo '<h1>Ana Kategori İşlemleri</h1><br />';
      $valid->inRange($title,75,1,'Başlık doldurulmalı ve en fazla 75 karakter olmalıdır.');
      $valid->inRange($info,150,1,'Açıklama doldurulmalı ve en fazla 150 karakter olmalıdır.');
      $valid->inRange($order,5,1,'Sıra doldurulmalı ve en fazla 5 karakter olmalıdır.');
      $valid->isNumber($order,'Sıra sadece rakam olmalıdır.');

      if ($valid->isError()) $valid->listErrors();
      else {
        // id, title, info, name, active, parent, order, lang, date
        $name=makeNicer($title);
        $name=checkNiceName($name,$CATEGORIES_TABLE);
        $q=$mysql->query("insert into $CATEGORIES_TABLE values('','$title','$info','$name','$active','0','$order','$lang','$date')");
        if ($q) echo 'Yeni ana kategori eklendi';
        else echo 'Ana kategori eklenirken hata oluştu!';
      }
    }
/**************************************************************************************************************************************/
    elseif ($what=='subcat') { # alt menü ekle
      // id, title, info, name, active, parent, order, lang, date
      echo '<h1>Alt Kategori İşlemleri</h1><br />';
      $valid->inRange($title,75,1,'Başlık doldurulmalı ve en fazla 75 karakter olmalıdır.');
      $valid->inRange($info,150,1,'Açıklama doldurulmalı ve en fazla 150 karakter olmalıdır.');
      $valid->inRange($order,5,1,'Sıra doldurulmalı ve en fazla 5 karakter olmalıdır.');
      $valid->isNumber($order,'Sıra sadece rakam olmalıdır.');

      if ($valid->isError()) $valid->listErrors();
      else {
        // id, title, info, name, active, parent, order, lang, date
        $name=makeNicer($title);
        $name=checkNiceName($name,$CATEGORIES_TABLE);

        $q=$mysql->query("insert into $CATEGORIES_TABLE values('','$title','$info','$name','$active','$parantCat','$order','$lang','$date')");
        if ($q) echo 'Yeni alt kategori eklendi';
        else echo 'Alt kategori eklenirken hata oluştu!';
      }
    }
/**************************************************************************************************************************************/
    elseif ($what=='exchange') { # kur ekle, güncelle
      echo '<h1>Kur İşlemleri</h1><br />';
      $exchange=str_replace(',','.',$exchange);
      $valid->inRange($name,10,1,'Kur adı doldurulmalı ve en fazla 10 karakter olmalıdır.');
      $valid->inRange($exchange,5,1,'Kur doldurulmalı ve en fazla 5 karakter olmalıdır.');
      $valid->isNumber($exchange,'Kur sadece rakam olmalıdır.');

      if ($valid->isError()) $valid->listErrors();
      else {
        $exchange=round($exchange,2);
        // id, name, exchange, date, active
        if ($do=='add') {
          $q=$mysql->query("insert into $EXCHANGES_TABLE values('','$name','$exchange','$date','$active')");
          if ($q) echo 'Yeni kur eklendi';
          else echo 'Kur eklenirken hata oluştu!';
        }
        else {
          $q=$mysql->query("update $EXCHANGES_TABLE set name='$name',exchange='$exchange',date='$date',active='$active' where id='$id'");
          if ($q) echo 'Yeni kur güncellendi';
          else echo 'Kur güncellenirken hata oluştu!';
        }
      } // else
    }
/**************************************************************************************************************************************/
    elseif ($what=='brand') { # marka ekle, güncelle
      $image=@$_FILES['image'];
      $valid->inRange($title,255,1,'Marka adı doldurulmalı ve en fazla 10 karakter olmalıdır.');
      $valid->inRange($order,3,1,'Sıra doldurulmalı ve en fazla 5 karakter olmalıdır.');
      $valid->isNumber($order,'Sıra sadece rakam olmalıdır.');
      if($do=='add') $valid->isEmpty($image,'Marka fotoğrafı girilmeli.');

      //id, title, name, image, date, order, active
      echo '<h1>Marka İşlemleri</h1><br />';
      if ($valid->isError()) $valid->listErrors();
      else {
        $date=time()+(60*$TIME_CORRECTION);
        $image=@$_FILES['image'];
        $upload=new imageUpload();
        $upload->maxHeight=65;
        $upload->maxWidth=150;
        $upload->uploadPath='img/brands';
        $name=makeNicer($title);
        $name=checkNiceName($name,$BRANDS_TABLE);

        if ($do=='add') {
          $test=$upload->upload($image);
          if (!$test) $upload->listErrors();
          else {
            // id, title, name, image, date, order, active
            $image_name=$upload->saveImg(0);
            $q=$mysql->query("insert into $BRANDS_TABLE values('','$title','$name','$image_name','$date','$order','$active')");
            if ($q) echo 'Yeni marka eklendi';
            else {
              echo 'Marka eklenirken hata oluştu!';
              unlink($upload->uploadPath.'/'.$image_name);
            }
          }
        }
        else {
          if (empty($image)) {
            $image_name=$upload->saveImg(0);
            $image="image='$image_name',";
          }
          else $image='';
          $q=$mysql->query("update $BRANDS_TABLE set $image`order`='$order',title='$title',name='$name',date='$date',active='$active' where id='$id'");
          if ($q) echo 'Marka güncellendi';
          else echo 'Marka güncellenirken hata oluştu!';
        }
        $upload->destructor();
      } // else
    }
/**************************************************************************************************************************************/
    elseif ($what=='options') { # genel ayarlar
      $valid->inRange($site_title,255,1,'Site başlığı boş bırakılmamalı ve en fazla 255 karakter olmalıdır.');
      $valid->checkEmail($site_admin_mail,'Geçersiz yönetici email adresi');
      $valid->checkEmail($site_contact_mail,'Geçersiz destek email adresi');
      $valid->inRange($item_display_column,255,1,'Kategorideki sütun boş bırakılmamalı ve en fazla 255 karakter olmalıdır.');
      $valid->inRange($items_per_category,255,1,'Kategoridedeki ürün boş bırakılmamalı ve en fazla 255 karakter olmalıdır.');
      $valid->inRange($item_home_total,255,1,'Ana Sayfadaki Ürün boş bırakılmamalı ve en fazla 255 karakter olmalıdır.');
      $valid->inRange($brand_per_row,255,1,'Bir Satırdaki Marka boş bırakılmamalı ve en fazla 255 karakter olmalıdır.');
      $valid->isNumber($items_per_category,'Kategoridedeki ürün sadece rakam olmalıdır.');
      $valid->isNumber($item_display_column,'Kategorideki sütun sadece rakam olmalıdır.');
      $valid->isNumber($item_home_total,'Ana Sayfadaki Ürün sadece rakam olmalıdır.');
      $valid->isNumber($brand_per_row,'Bir Satırdaki Marka sadece rakam olmalıdır.');

      echo '<h1>Genel Ayarlar</h1><br />';
      if ($valid->isError()) $valid->listErrors();
      else {
         $mysql->query("update $OPTIONS_TABLE set value='$site_title' where id='1'");
         $mysql->query("update $OPTIONS_TABLE set value='$site_admin_mail' where id='2'");
         $mysql->query("update $OPTIONS_TABLE set value='$site_contact_mail' where id='3'");
         $mysql->query("update $OPTIONS_TABLE set value='$user_email_valid' where id='4'");
         $mysql->query("update $OPTIONS_TABLE set value='$user_approve' where id='5'");
         $mysql->query("update $OPTIONS_TABLE set value='$items_per_category' where id='6'");
         $mysql->query("update $OPTIONS_TABLE set value='$item_display_column' where id='7'");
         $mysql->query("update $OPTIONS_TABLE set value='$item_home_total' where id='8'");
         $mysql->query("update $OPTIONS_TABLE set value='$brand_per_row' where id='9'");
         $mysql->query("update $OPTIONS_TABLE set value='$welcome_mail' where id='10'");
         $mysql->query("update $OPTIONS_TABLE set value='$show_item_price' where id='11'");

         echo 'Ayarlar güncellendi';
      }
    } // elseif
/**************************************************************************************************************************************/
    elseif ($what=='item') {
      $valid->inRange($title,100,1,'Ürün başlığı doldurulmalı ve en fazla 100 karakter olmalıdır.');
      $valid->inRange($info,255,1,'Ürün açıklaması doldurulmalı ve en fazla 255 karakter olmalıdır.');
      $valid->inRange($content,65000,1,'Ürün içeriği doldurulmalı ve en fazla 65000 karakter olmalıdır.');
      $valid->inRange($order,3,1,'Sıra doldurulmalı ve en fazla 5 karakter olmalıdır.');
      $valid->isNumber($order,'Sıra sadece rakam olmalıdır.');
      //$valid->isEmpty($image,'Ürün fotoğrafı girilmeli.');

      echo '<h1>Ürün Ekle</h1><br />';
      if ($valid->isError()) $valid->listErrors();
      else {
        $image=@$_FILES['image'];
        $test=true;
        if (!$home) $home=0;
        if (!$new) $new=0;
        if (!$show_price) $show_price=0;
        if ($image['size']>0) {
          $upload=new imageUpload();
          $test=$upload->upload($image);
          if (!$test) $upload->listErrors();
        }

        if ($test) {
          // id, item, summary, info, name, home, new, lang, show_price, xml_code, image, date, brand_id, active, order, stock
          $image_name='';
          if ($image['size']>0) $image_name=$upload->saveImg(1);
          elseif (count($_SESSION['imgList']>0)) {
              $image_name=$_SESSION['imgList'][0];
              unset($_SESSION['imgList'][0]);
          }
          $image_name=$mysql->escape($image_name);
          $date=time()+(60*$TIME_CORRECTION);
          $name=makeNicer($title);
          $name=checkNiceName($name,$ITEMS_TABLE);

          $q=$mysql->query("insert into $ITEMS_TABLE values('','$title','$info','$content','$name','$home','$new','$lang','$show_price','$xml_code','$image_name','$date','$brand','$active','$order','0')");
          if (!$q) {
            echo 'Ürün eklenriken hata oluştu<br />';
            if ($image['size']>0) {
              unlink($upload->uploadPath.'/'.$image_name);
              unlink($upload->thumbMidPath.'/'.$image_name);
              unlink($upload->thumbSmallPath.'/'.$image_name);
              unset($_SESSION['imgList']);
            }
          }
          else {
            // id, item_id, cat_id, primary
            $item_id=$mysql->lastId;
            $mysql->query("insert into $ITEM_CATS_TABLE values('','$item_id','$parantCat','1')");
            if (!empty($cats)) {
              $cats=explode(',',$cats);
              foreach ($cats as $cat) $mysql->query("insert into $ITEM_CATS_TABLE values('','$item_id','$cat','0')");
            }
            if (count($_SESSION['imgList']>0)) {
              foreach ($_SESSION['imgList'] as $image) {
                $image=$mysql->escape($image);
                //id, item_id, image, active, date
                $mysql->query("insert into $IMAGES_TABLE values('','$item_id','$image','1','$date')");
              }
            }
            unset($_SESSION['imgList']);
            header("location: $SITE_URL/index.php?page=item&id=$item_id");
            //echo '<a href="'.$SITE_URL.'/index.php?page=item&id='.$item_id.'" />';
            //echo 'Ürün sayfasından ürün fiyatlarını ve ek fotoğraflarını ekleyebilirsiniz.</a><br />';
          }
        } // else
      } // else
    }
/**************************************************************************************************************************************/
    elseif ($what=='itemphotoadd') {
      $image=@$_FILES['itemphoto'];
      $item_id=@(int)$_POST['item_id'];
      if ($item_id<1) echo 'geçersiz işlem';
      elseif (empty($image)) echo 'İmaje seçmelisiniz';
      else {
        $upload=new imageUpload();
        $test=$upload->upload($image);
        if (!$test) $upload->listErrors();
        else {
          $image_name=$upload->saveImg(1);
          $date=time()+(60*$TIME_CORRECTION);

          $q=$mysql->query("select image from $ITEMS_TABLE where id='$item_id'");
          $isImage=$mysql->result($q,'image');
          if (empty($isImage)) {
            //id, item, summary, info, name, home, new, lang, show_price, xml_code, image, date, brand_id, active, order, stock
            $q=$mysql->query("update $ITEMS_TABLE set image='$image_name' where id='$item_id'");
            if ($q) echo 'Ürün imajı eklendi.<br />';
            else {
              echo 'ürün imajı eklenemedi.<br />';
              unlink($upload->uploadPath.'/'.$image_name);
              unlink($upload->thumbMidPath.'/'.$image_name);
              unlink($upload->thumbSmallPath.'/'.$image_name);
             }
          }
          else {
            //id, item_id, image, active, date
            $q=$mysql->query("insert into $IMAGES_TABLE values('','$item_id','$image_name','1','$date')");
            if ($q) echo 'Ürün imajı eklendi.<br />';
            else {
              echo 'ürün imajı eklenemedi.<br />';
              unlink($upload->uploadPath.'/'.$image_name);
              unlink($upload->thumbMidPath.'/'.$image_name);
              unlink($upload->thumbSmallPath.'/'.$image_name);
            }
          }
          echo goBack();
        }
      }
    }
/**************************************************************************************************************************************/
  }
  else echo '2-geçersiz kullanım!';
}

?>
<a rel="shadowbox;width=1;height=1" title="fix" href=""></a>
    </p>
    </div>
<!--//div:icerik -->